package com.yaodian100.ec.order.service;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.DomainService;
import com.yaodian100.ec.order.entity.InboundTrackingCase;
import com.yaodian100.ec.order.entity.OrderProduct;
import com.yaodian100.ec.order.entity.Orders;
import com.yaodian100.ec.order.entity.ServiceOrderDetail;
import com.yaodian100.ec.order.entity.ServiceOrderProduct;
import com.yaodian100.ec.order.entity.ServiceOrders;
import com.yaodian100.ec.order.remote.ServiceOrderBo;
import com.yaodian100.ec.order.rule.Return;
import com.yaodian100.ec.order.service.impl.ServiceOrderHelper;

public interface ServiceOrderService extends DomainService<ServiceOrders> {

	public ServiceOrders saveServiceOrders(Orders order, ServiceOrders serviceOrder, Collection serviceOrderProd,
			Boolean mustSyncToERP) throws CoreException;

	@Transactional(readOnly = false)
	public void saveServiceOrderProd(ServiceOrderProduct serviceOrderProduct) throws CoreException;

	public void saveOrderDetail(ServiceOrderDetail serviceOrderDetail) throws CoreException;

	public List<ServiceOrderProduct> getServiceOrderProdList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	public List<ServiceOrderDetail> getServiceOrderDetailList(int firstResult, int maxResults, CommonCriteria criteria,
			String[] sortOrder) throws CoreException;

	public ServiceOrders update(ServiceOrders serviceOrder);

	// public ServiceOrders changeProduct();
	public void updateServiceOrderStatus(ServiceOrderBo sob);

	public void confirmReturnProduct(String serviceId);

	public void cancelReturnProduct(String serviceId);

	public void sendMail(Orders order, ServiceOrders serviceOrder, Object[] sops);

	public void sendMail(String velocityTemplate, String mailSubject, Orders order);

	public void sendMailForReturnNote(Orders order, ServiceOrders so, Object[] sops);

	public void sendMailForReturnDone(Orders order, ServiceOrders so, Object[] sops);

	public void sendMailForChangeNote(Orders order, ServiceOrders so, Object[] sops);

	public void sendMailForChangeDone(Orders order, ServiceOrders serviceOrder, Object[] sops);

	public void sendMailForChangeFail(Orders order, ServiceOrders serviceOrder, Object[] sops);

	public void sendMailForReturnFail(Orders order, ServiceOrders serviceOrder, Object[] sops);

	public void sendMailForRefund(Orders order, ServiceOrders so, Object[] sops);

	public void sendMailForReturnProductConfirm(Orders order, ServiceOrders serviceOrder, Object[] sops);

	public ServiceOrders cancelOrderByUser(String orderId, String description, String reason, String memberId,
			String clientIp, String b2eId);

	public ServiceOrders cancelOrderBySystem(String orderId, String description, String reason, String memberId,
			String clientIp, String b2eId);

	public void createCancelOrderForSyncOrder(String orderId, String description, String reason, String memberId,
			String clientIp, String b2eId);

	public void returnInventory(Orders order);

	public ServiceOrders prepareReturnShipfareSO(Orders order, BigDecimal returnShipfare, String memo);

	public String returnAllProduct(String orderId, String memberId, String[] orderProdId, String[] accessaryDescription,
			String[] reason, String[] description, String receiverName, String receiverAddr, String receiverArea,
			String receiverCity, String receiverExt, String clientIp, String receiverMobile, String receiverPhone,
			String receiverPhoneArea, String receiverProvince, String receiverZip, String b2eId);

	public ServiceOrderHelper returnProductByOrderProdId(String orderProdId, String memberId,
			String accessaryDescription, String paymentTp, String receiverName, String receiverAddr, String receiverArea,
			String receiverCity, String receiverExt, String clientIp, String receiverMobile, String receiverPhone,
			String receiverPhoneArea, String receiverProvince, String receiverZip, String reason, String description,
			String srcType, String orderId, String b2eId, String[] prodSpecIds, String[] qtys, String orderSt,
			String oldServiceId, String orderDetailId);

	public ServiceOrderHelper changeProductByOrderProdId(String orderProdId, String memberId,
			String accessaryDescription, String paymentTp, String receiverName, String receiverAddr, String receiverArea,
			String receiverCity, String receiverExt, String clientIp, String receiverMobile, String receiverPhone,
			String receiverPhoneArea, String receiverProvince, String receiverZip, String reason, String description,
			String srcType, String orderId, String b2eId, String[] specParameters, String oldServiceId);

	public ServiceOrderHelper changeProductByServiceId(String serviceId, String memberId, String accessaryDescription,
			String paymentTp, String receiverName, String receiverAddr, String receiverArea, String receiverCity,
			String receiverExt, String clientIp, String receiverMobile, String receiverPhone, String receiverPhoneArea,
			String receiverProvince, String receiverZip, String reason, String description, String srcType, String orderId,
			String b2eId, String[] specParameters);

	public ServiceOrders cancelOrderByCsrUpdateOrder(Orders order, String description, String reason, String memberId,
			String clientIp, String b2eId, String userId, List<OrderProduct> cancelProducts);

	public void returnShipfare(String trxType, String memberId, String trxTypeId, float trxAmount, Date trxDate,
			String description, String jobId, Date refundDate) throws Exception;

	public Return calculateReturn(String orderProdId, String[] prodSpecIds, String[] qtys);

	public void refundForPaid(ServiceOrders so, ServiceOrderBo sob);
	
	public List<ServiceOrders> getServiceOrderListByOrderProductId(Long orderProdId);

	/**
	 * 依 order detail 查詢相符的 service order
	 */
	public List<ServiceOrders> getServiceOrderListByOrderDetailId(Long orderDetailId);

	public ServiceOrderDetail latestServiceOrderDetailByOrderDetailId(Long orderDetailId);

	/**
	 * 判斷某筆 orderDetailId 是否可以退換貨
	 */
	public boolean isOrderDetailReturnableChangable(Long orderDetailId);

	/*
	 * 退还溢收运费
	 */
	public void returnShipfareException(String orderId, Float shipfare);

	public List<ServiceOrders> getServiceOrderListByOrderId(String orderId);

	public boolean isNewServiceOrderCreatableByOrderId(String orderId);

	public boolean revertCancel(String serviceId);

	public String cancelServiceOrderByERP(String serviceId);

	public InboundTrackingCase saveOrUpdateInboundTrackingCase(InboundTrackingCase inboundTrackingCase);

	public List<InboundTrackingCase> getInboundTrackingCase(Map<String, Object> trackCaseMap);

	public InboundTrackingCase getInboundTrackingCaseByCaseId(Long caseId);
	
	public ServiceOrders cancelOrderBySystemSplit(Orders orderSrc);
}
